package part1.api.io;

import java.io.BufferedWriter;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.nio.charset.StandardCharsets;

/**
 * 缓冲字符流-----最常用的读写字符串的流
 * 是一对高级流，并且是字符流
 * 内部维护一个默认8kb(8192)长度的char数组，还是块读写形式读写字符以提高读写效率
 * BufferedWriter和BufferedReader
 *
 *PrintWriter:按行写入
 */
public class PWDemo {
    public static void main(String[] args) throws Exception{
        //最常用写入字符串方式
        //底层连接了BufferedWriter,连接了OutputStreamWriter,连接了FileOutputStream
        PrintWriter pw = new PrintWriter("pw.txt");
        pw.println("你好中国");
        pw.println("世界那么大");
        System.out.println("写出完毕");
        pw.close();

        FileOutputStream fos = new FileOutputStream("pw.txt");
        OutputStreamWriter osw = new OutputStreamWriter(fos, StandardCharsets.UTF_8);
        BufferedWriter bw = new BufferedWriter(osw);
        PrintWriter pp = new PrintWriter(bw);
        pp.println("你好中国");
        pp.println("走啊走一起走");
        System.out.println("写出完毕");
        bw.close(); //先调用flush()冲水
    }
}
